<?php

/**
 * Author: Thu Bach
 * Created: 20141115
 * Description: a controller is serving for testing
 */	

class TestController extends ControllerBase
{
	/*
	 * Goal: test the insert function for Attribute collection
	 * Last updated: 20141115
	 * Author: Thu Bach
	 * 
	 * @Route
	 */
	public function insAttributeAction($description, $entity, $view, $attribute)
	{
		//$description = $this->dispatcher->getParam("description");
		//$entity = $this->dispatcher->getParam("entity");
		//$view = $this->dispatcher->getParam("view");
		//$attribute = $this->dispatcher->getParam("attribute");
		
		/*
		 * Debug, show error
		 */
		if (!ini_get('display_errors')) {
		    ini_set('display_errors', '1');
		}
		/*End Debug*/
		
		$att = new Attributes();
		$att->Description = $description;
		$att->EntityCode = $entity;
		$att->View = $view;
		$att->Attribute = $attribute;
		$att->Modifier = 'thubach';
		$att->ModifiedDate = "20141115";
		
		if($att->save()==FALSE)
		{
			echo "We can't insert right now \n";
			foreach ($attribute->getMessages() as $message) 
			{
				echo $message, "\n";
			}
		}
		else 
		{
			echo "Great, a new record was saved successfully!";	
		}
	}
	
	public function testAction($id)
	{
		echo $id;
	}
	
	public function getAttributeEntityAction($entity)
	{
		/*
		 * Debug, show error
		 */
		if (!ini_get('display_errors')) {
		    ini_set('display_errors', '1');
		}
		/*End Debug*/
		
		$att = new Attributes();
		$arr = $att->getAttributeEntity($entity);
		//return $arr = $att->getAttributeEntity($entity);
		foreach ($arr as $atr)
		{
			foreach($atr as $key=>$value)
			{
				echo $key . ": " . $value . " \n";
			}
		}
		
	}
}